<?php
/**
 * Created by PhpStorm.
 * User: Dinh Thi
 * Date: 1/19/15
 * Time: 12:12 PM
 */

namespace DinhThi\MVC\Model;
use DinhThi\MVC\Configuration;
use PDO;
use Exception;
class MySQLDatabase extends PDO{
    public function __construct(){
        try{
            $config = Configuration::getInstance();
            $mysqlHost = $config->getProperty('MysqlServer.host');
            $mysqlUsername = $config->getProperty('MysqlServer.user');
            $mysqlPassword = $config->getProperty('MysqlServer.password');
            $mysqlDB = $config->getProperty('MysqlServer.database');
            parent::__construct("mysql:host=".$mysqlHost.";dbname=".$mysqlDB, $mysqlUsername, $mysqlPassword, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
        }
        catch(Exception $e){
            echo 'Database connection error!';
            exit;
        }
    }
} 